package cn.ecnu.user.controller;

import cn.ecnu.user.service.UserService;
import cn.ecnu.user.util.AuthSolver;
import cn.ecnu.user.vo.EmailPasswordVo;
import cn.ecnu.user.vo.UsernamePasswordVo;
import cn.ecnu.user.vo.RegisterWithUsernameVo;
import cn.ecnu.user.vo.UserInfoVo;
import cn.ecnu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private UserService userService;

    // 登录, 使用手机号和密码
    @PostMapping("/loginWithUsername")
    public R loginWithPassword(@RequestBody UsernamePasswordVo vo) {
        UserInfoVo info = userService.loginWithPassword(vo);
        return R.ok().put("data", info);
    }

    // 登录, 使用手机验证码
    @PostMapping("/loginWithEmail")
    public R loginWithCaptcha(@RequestBody EmailPasswordVo vo) {
        UserInfoVo info = userService.loginWithEmail(vo);
        return R.ok().put("data", info);
    }

    // 注册, 使用手机号注册
    @PostMapping("/register")
    public R registerWithPhone(@RequestBody RegisterWithUsernameVo vo) {
        userService.registerWithUser(vo);
        return R.ok();
    }
}
